import wx
import pandas as pd

def _pydate2wxdate(date):
    import datetime
    assert isinstance(date, (datetime.datetime, datetime.date))
    tt = date.timetuple()
    dmy = (tt[2], tt[1] - 1, tt[0])
    return wx.DateTimeFromDMY(*dmy)

def _wxdate2pydate(date):
    import datetime
    assert isinstance(date, wx.DateTime)
    if date.IsValid():
        ymd = map(int, date.FormatISODate().split('-'))
        return datetime.date(*ymd)
    else:
        return None

from wx.grid import Grid
def show_df(grid:Grid,df):

    grid.ClearGrid()
    #grid.NumberRows = len(df)
    #grid.NumberCols = len(df.columns)

    grid.SetRowSize(0, 60)
    grid.SetColSize(0, 150)

    for i, col in enumerate(list(df.columns)):
        grid.SetColLabelValue(i,col)

    if type(df.index) is pd.MultiIndex:
        for i, row in enumerate(list(df.index)):
            grid.SetRowLabelValue(i, str(df.index))
    else:
        for i, row in enumerate(list(df.index)):
            grid.SetRowLabelValue(i, str(row))

    i = 0
    for index, row in df.iterrows():
        for j in range(len(row)):
            grid.SetCellValue(i, j, str(row[j]))
        i += 1